<?php

namespace App\Console\Commands;

use App\Morefun\Prize\ExchangeRecordSynchronizer;
use Illuminate\Console\Command;

class ExchangeRecordSync extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'sync:exchange';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Sync exchange records from redis to database.';

    /**
     * Create a new command instance.
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     * @param $synchronizer ExchangeRecordSynchronizer
     * @return mixed
     */
    public function handle(ExchangeRecordSynchronizer $synchronizer)
    {
        try {
            $synchronizer->sync();
            $this->line('同步成功');
        } catch (\Exception $exception) {
            $this->warn($exception->getMessage());
        }
    }
}
